package com.stu.controller;

import cn.hutool.extra.qrcode.QrCodeUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;

/**
 * 公共模块
 *  上传、下载、excel 导出 、erma生成
 *  http://localhost:8080/common/erma2
 *  ->  http://localhost:8080/back/stuForm.html
 */
@Slf4j
@RequestMapping("/common")
@RestController
public class CommonController {

    @Value("${stuoa.url}")
    private String url;

    @RequestMapping("/erma2")
    public OutputStream erma(HttpServletResponse response) throws IOException {
        // 二维码内容
//        log.info("二维码网址:{}",str);
        // 生成二维码并指定宽高
        BufferedImage generate = QrCodeUtil.generate(url, 300, 300);
        //获得输出流
        ServletOutputStream out = response.getOutputStream();
        try {
            ImageIO.write(generate, "jpg", out);
        } catch (IOException e) {
//            return e.getMessage();
        }
        return out;
    }
}
